package com.pet.cart.controller;


import com.pet.cart.domain.vo.FavorVO;
import com.pet.cart.service.IFavorService;
import com.pet.common.domain.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品收藏表 前端控制器
 * </p>
 *
 * @author Cookies
 * @since 2024-07-11
 */
@Api(tags = "商品收藏服务接口")
@RestController
@RequestMapping("/favors")
@RequiredArgsConstructor
public class FavorController {
    private final IFavorService favorService;

    @PostMapping("/{id}")
    @ApiOperation("添加商品收藏")
    public Result addItems2Favor(@PathVariable Integer id) {
        return favorService.addItems2Favor(id);
    }

    @GetMapping
    @ApiOperation("获取用户收藏列表")
    public Result getFavorListByUser() {
        List<FavorVO> favorVOList = favorService.getFavorListByUser();
        return Result.success(favorVOList);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除商品收藏")
    public Result deleteFavor(@PathVariable Integer id) {
        boolean isSucceed = favorService.removeById(id);
        return isSucceed ? Result.success() : Result.error();
    }
}
